package com.wash.shoes.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wash.shoes.entity.CustomerPo;
import com.wash.shoes.mapper.CustomerMapper;
import com.wash.shoes.mapper.OrderMapper;
import com.wash.shoes.page.PageFactory;
import com.wash.shoes.service.CustomerService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 客户 服务实现类
 * </p>
 *
 * @author ljg
 * @since 2024-08-28
 */
@Log4j2
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, CustomerPo> implements CustomerService {


    @Resource
    OrderMapper orderMapper;

    @Override
    public Page<CustomerPo> pageList(CustomerPo customerPo) {
        Page<CustomerPo> page = PageFactory.defaultPage();
        List<CustomerPo> dataList = baseMapper.pageList(page, customerPo);
        page.setRecords(dataList);
        return page;
    }

    @Override
    public CustomerPo getByPhone(String receiverMobile) {
        return this.baseMapper.getByPhone(receiverMobile);
    }

    @Override
    public Integer updateOrderNum() {
        Page page = new Page();
        page.setSize(100000);
        page.setCurrent(1);
        List<CustomerPo> dataList = baseMapper.pageList(page, null);

        for (CustomerPo customerPo : dataList) {
            Integer count = orderMapper.getByPhone(customerPo.getPhone(), "6");
            customerPo.setOrderNum(count);
            this.baseMapper.updateById(customerPo);
        }
        return 1;
    }


    @Override
    public CustomerPo getByOpenId(String openId) {
        return this.baseMapper.getByOpenId(openId);
    }

    @Override
    public CustomerPo getByInviteCode(String code) {
        return this.baseMapper.getByInviteCode(code);
    }

    @Override
    public CustomerPo getByDyOpenId(String dyOpenId) {
        return this.baseMapper.getByDyOpenId(dyOpenId);
    }
}